package com.trust;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.MalformedInputException;

public class MyBatisRM {
    public static void main(String[] args) throws IOException {
        //从xml配置文件中创建SqlSessionFactory
        //使用建造者模式获取SqlSessionFactoryBuilder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        //得到全局配置文件
        final InputStream resourceAsStream = Resources.getResourceAsStream("config.xml");
        //使用建造者模式中的build方法去获取sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = builder.build(resourceAsStream);
        //获取sqlsession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //selectOne
        int count = sqlSession.selectOne("star.count");
        System.out.println(count);

    }
}